1487B - Cat Cycle - CodeForces Solution


math number theory *1200

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n,k = map(int,input().split()); k -= 1
    a = n//2;g = k//a;e = k + g
    print([k%n+1,e%n+1][n%2])

C++ Code:

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(long long  i=a;i<b;i++)
#define decrep(i,a,b)        for(long long  i=a;i>=b;i--)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define ll  long long
#define nl "\n"
#define pb push_back
#define no cout<<"NO\n"
#define yes cout<<"YES\n"
#define all(v) v.begin(),v.end()
#define dec(v) v.rbegin(),v.rend()
#define decimal(n) fixed<<setprecision(n)
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
 
// #define set(name,data,size) memset(name,data,size);
 ll add(ll x)
 {
    ll mx=0;
    ll mn=10;
    while(x>0)
    {
       ll rem=x%10;
       x=x/10;
       mx=max(mx, rem);
       mn=min(mn, rem);
    }
    return mn*mx;
 
 
 }
 
 bool mycmp(pair<ll,ll>&a,pair<ll,ll>&b)
 {
      if(a.first< b.first)
      {
         return true;
      }
      else if(a.first==b.first && a.second< b.second)
       {
         return true;
       }
       return false;
 }

void dfs(ll src, ll n, vector<pair<ll,ll>>&v, vector<bool>&vis)
{
   vis[src]=true;
   for(ll i=0;i<n;i++)
   {
     if(  (v[i].first==v[src].first  || v[i].second==v[src].second )    && vis[i]==false)
        {
           dfs(i, n, v,vis);

        }
   }
}
void  jaishreekrishna()
{  



  ll n, k;
  cin>>n;
  cin>>k;

 if(n%2==0)
 {
    ll pos=k%n;
    if(pos==0)
    {
       cout<<n<<endl;
       return ;
    }
    cout<<pos<<endl;

   return ;
 }

 ll pos=k+(k-1)/(n/2);
 pos=pos%n;
    if(pos==0)
    {
       cout<<n<<endl;
       return ;
    }
    cout<<pos<<endl;
 


}

 
int main()
{
  ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
















 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  while(t--)
  {
         jaishreekrishna();
  }
  cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
	cerr<<__DATE__<<nl<<__TIME__<<nl;
 
return 0;
 
}


Comments

Submit
0 Comments
More Questions

Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal